package pers.lolicer.redtidelibrary.repository

import android.content.Context
import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import pers.lolicer.redtidelibrary.repository.dao.BookDao
import pers.lolicer.redtidelibrary.repository.entity.BookEntity

@Database(
    version = 1,
    entities = [BookEntity::class],
    exportSchema = false
)

abstract class MyDatabase:RoomDatabase() {
    companion object{
        private var db:MyDatabase?=null
        private val dbName = "book"

        fun getDB(context: Context)=if(db == null){
            Room.databaseBuilder(context, MyDatabase::class.java, name = dbName).enableMultiInstanceInvalidation().build().apply {
                db = this
            }
        }else{
            db!!
        }
    }

    abstract fun getBookDao(): BookDao
}